{include file="public/head"}
<body>
<div class="x-body">
    <div class="lotus-nav">
        <button class="layui-btn layui-btn-sm" onclick="x_admin_show('添加角色','addRole.html',500,400)">
            <i class="layui-icon layui-icon-add-1"></i>添加角色
        </button>

        <button class="layui-btn layui-btn-sm layui-btn-normal" onclick="m_admin_show('批量授权','batchLicensing.html','40%')">
            <i class="layui-icon layui-icon-group"></i>批量授权
        </button>

        <div class="layui-input-inline">
            <input id="search" name="search" class="layui-input lotus-input" placeholder="请输入登录名搜索" value="{$Think.get.title}">
        </div>
        <button class="layui-btn layui-btn-sm" onclick="search()"><i class="layui-icon layui-icon-search"></i></button>

        <span class="x-right">共有数据:{$role->total()}条
            <button onclick="javascript:location.reload()" class="layui-btn-default">
                <i class="icon iconfont">&#xe6aa;</i>
            </button>
        </span>
    </div>

    <table class="layui-table">
        <thead>
        <tr>
            <th style="width: 40px;text-align: center">ID</th>
            <th>角色</th>
            <th style="width: 40px;text-align: center">排序</th>
            {if $type == 1}
            <th style="width: 80px;text-align: center">公司类型</th>
            <th style="width: 60px;text-align: center">管理员</th>
            {/if}
            <th style="width: 40px;text-align: center">状态</th>
            <th style="width: 205px;text-align: center">操作</th>
        </thead>
        <tbody>
        {volist name='role' id='vo'}
        <tr>
            <td style="text-align: center">{$i}</td>
            <td>{$vo.title}</td>
            <td style="text-align: center">{$vo.sort}</td>
            {if $type == 1}
            <td style="text-align: center">
                {eq name='$vo["type"]' value="1"}
                总公司
                {else/}
                子公司
                {/eq}
            </td>
            <td style="text-align: center">
                {eq name='$vo["concierge"]' value="1"}
                <span style="font-weight: bold;color:green">是</span>
                {else/}
                <span style="font-weight: bold;color:red">否</span>
                {/eq}
            </td>
            {/if}
            <td style="text-align: center">
                {eq name='$vo["status"]' value="1"}
                <span style="font-weight: bold;color:green">启用</span>
                {else/}
                <span style="font-weight: bold;color:red">禁用</span>
                {/eq}
            </td>
            <td>
                {if $vo.sign == 3}
                <button class="layui-btn layui-btn-xs layui-btn-normal"
                        onclick="m_admin_show('{$vo.title}授权','updateAuthGroupRule.html?id={$vo.id}','40%')">授权
                </button>
                <button class="layui-btn layui-btn-xs"
                        onclick="x_admin_show('角色编辑','editRole.html?id={$vo.id}',500,350)">编辑
                </button>
                <button class="layui-btn layui-btn-xs layui-btn-warm"
                        onclick="x_admin_show('角色复制，附带权限','copyRole.html?id={$vo.id}',500,300)">角色复制
                </button>
                <button onclick="delRole(this,'{$vo.id}')" class="layui-btn layui-btn-xs layui-btn-danger">删除</button>
                {elseif $vo.sign == 2}
                <button class="layui-btn layui-btn-xs layui-btn-normal"
                        onclick="m_admin_show('{$vo.title}授权','updateAuthGroupRule.html?id={$vo.id}','40%')">授权
                </button>
                <button class="layui-btn layui-btn-xs layui-btn-warm"
                        onclick="x_admin_show('角色复制，附带权限','copyRole.html?id={$vo.id}',500,300)">角色复制
                </button>
                {/if}
            </td>
        </tr>
        {/volist}
        </tbody>
    </table>
    <div class="page">
        <div>
            {$role->render()}
        </div>
    </div>
</div>
</body>
{include file="public/foot"}
<script>
    function search() {
        var title = $("#search").val();
        location.href = "role.html?title=" + title;
    }
    function addRole() {
        var role_name = $("#role_name").val();
        if (role_name.length == 0) {
            layer.msg('角色名不能为空', {icon: 2});
            return false;
        }
        if (role_name.length < 2) {
            layer.msg('角色名过短', {icon: 2});
            return false;
        }
        $.ajax({
            url: 'addRole',
            type: 'post',
            dataType: 'json',
            data: {role_name: role_name},
        }).done(function (data) {
            // console.log(data);
            if (data.code == 1) {
                layer.msg(data.msg, {icon: 1, offset: "t", time: 500}, function () {
                    location.reload();
                });
            } else {
                layer.msg(data.msg, {icon: 2});
            }
        })
    }

    function delRole(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            $.ajax({
                url: 'delRole',
                type: 'post',
                dataType: 'json',
                data: {id: id},
            }).done(function (data) {
                if (data.code == 1) {
                    layer.msg(data.msg, {icon: 1, offset: "t", time: 500}, function () {
                        location.reload();
                    });
                } else {
                    layer.msg(data.msg, {icon: 2, offset: "t"});
                }
            })
        })
    }

</script>
